#ifndef WOLF_COLOR_HPP
#define WOLF_COLOR_HPP

#include "common.hpp"
namespace wolf {
/**
 * @brief An color utility
 * @ingroup utilMod
 *
 * It can converts itself to various formats, like
 *  the Uint32 pixel (used by SDL_FillRect() and SDL_BlitSurface())
 *  the SDL_Color an the hexa format (used on SDL_gfx functions).
 **/
class Color {
public:
	Color() {
		r = g = b = a = 0;
	}

	/**
	 * @brief Creates a color by the given components
	 *
	 *
	 **/
	Color(Uint8 r_, Uint8 g_, Uint8 b_, Uint8 a_ = 255) {
		r = r_;
		g = g_;
		b = b_;
		a = a_;
	}

	/**
	 * @brief Creates a color from a SDL_Color
	 *
	 *
	 **/
	Color(const SDL_Color &color) {
		r = color.r;
		g = color.g;
		b = color.b;
	}

	/**
	 * @brief Creates a color by given hex value
	 *
	 * It must follow the format RRGGBBAA.
	 **/
	Color(Uint32 hex) {
		r = hex >> 24;
		g = (hex >> 16) & 0xFF;
		b = (hex >> 8) & 0xFF;
		a = hex & 0xFF;
	}

	/**
	 * @brief Creates a color interpreting the pixel on the given pixelFormat
	 *
	 *
	 **/
	Color(Uint32 pixel, SDL_PixelFormat *format) {
		SDL_GetRGBA(pixel, format, &r, &g, &b, &a);
	}

	/**
	 * @brief Converts to SDL_Color
	 *
	 *
	 **/
	SDL_Color toSDL_Color() const {
		return ( SDL_Color )
		{
			r, g, b
		};
	}

	/**
	 * @brief Converts to Hexadecimal Representation
	 *
	 * It uses the format RRGGBBAA
	 **/
	Uint32 toHex() const {
		return Uint32(r) << 24 | Uint32(g) << 16 | Uint32(b) << 8 | Uint32(a);
	}

	/**
	 * @brief Converts to a pixel representation given by format
	 *
	 *
	 **/
	Uint32 toPixel(const SDL_PixelFormat *format) const {
		return SDL_MapRGBA(format, r, g, b, a);
	}

	/**
	 * @brief Returns the red component
	 *
	 *
	 **/
	Uint8 getR() const {
		return r;
	}

	/**
	 * @brief Returns the green component
	 *
	 *
	 **/
	Uint8 getG() const {
		return g;
	}

	/**
	 * @brief Returns the blue component
	 *
	 *
	 **/
	Uint8 getB() const {
		return b;
	}

	/**
	 * @brief Returns the alpha component
	 *
	 *
	 **/
	Uint8 getA() const {
		return a;
	}

	/**
	 * @brief sets the red component
	 *
	 *
	 **/
	void setR(Uint8 r_) {
		r = r_;
	}

	/**
	 * @brief sets the green component
	 *
	 *
	 **/
	void setG(Uint8 g_) {
		g = g_;
	}

	/**
	 * @brief sets the blue component
	 *
	 *
	 **/
	void setB(Uint8 b_) {
		b = b_;
	}

	/**
	 * @brief sets the alpha component
	 *
	 *
	 **/
	void setA(Uint8 a_) {
		a = a_;
	}
private:
	Uint8 r, g, b, a;
};

}

#endif // WOLF_COLOR_HPP
